<template>
  <div>
    <gm-title>
      <template v-slot:left-title> 书籍分类 </template>
    </gm-title>

    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide">
          <div class="book-class">
            <ul>
              <li v-for="item in startClassname" :key="item.id">
                <span class="iconfont icon-houses"></span>
                <span>{{ item.class }}</span>
              </li>
            </ul>

            <ul>
              <li v-for="item in centerClassname" :key="item.id">
                <span class="iconfont icon-houses"></span>
                <span>{{ item.class }}</span>
              </li>
            </ul>

            <ul>
              <li v-for="item in endClassname" :key="item.id">
                <span class="iconfont icon-houses"></span>
                <span>{{ item.class }}</span>
              </li>
            </ul>
          </div>
        </div>
        <div class="swiper-slide"></div>
      </div>
    </div>

    <gm-title>
      <template v-slot:left-title> 专题分类 </template>
    </gm-title>

    <div class="topic-sort">
      <ul>
        <li v-for="item in sortinfo" :key="item.id">
          <topic-sort :imgUrl="item.imgUrl"></topic-sort>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import gmTitle from "@/components/gmTitle.vue";
import topicSort from "@/components/topicSort.vue";

export default {
  name: "Sort",
  components: {
    gmTitle,
    topicSort,
  },
  data() {
    return {
      startClassname: [],
      centerClassname: [],
      endClassname: [],
      sortinfo: [],
    };
  },
  methods: {
    getData() {
      let url = "data/listen.json";
      let gms = axios.get(url);
      gms.then((res) => {
        this.startClassname = res.data.startBookclass;
        this.centerClassname = res.data.centerBookclass;
        this.endClassname = res.data.endBookclass;
        this.sortinfo = res.data.resultSort;
      });
    },
  },
  mounted() {
    this.getData();
    const mySwiper = new Swiper(".swiper-container", {
      slidesPerView: "auto",
      observer: true,
      spaceBetween: 20,
      freeMode: true,
    });
  },
};
</script>

<style lang="scss" scoped>
.book-class {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  ul {
    display: flex;
    width: 340px;
    li {
      background-color: rgb(244, 244, 244);
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 10px;
      margin: 6px 9px 6px 0;
      border-radius: 5px;
      flex-shrink: 0;
      span:first-child {
        font-size: 20px;
        padding-right: 8px;
      }
      span:nth-child(2) {
        font-size: 16px;
      }
    }
  }
}
.topic-sort {
  display: flex;
  justify-content: center;
  ul {
    width: 340px;
    li {
      width: 100%;
      margin-bottom: 6px;
    }
  }
}
</style>